package com.jin.lazytool.entity;


import com.github.kwhat.jnativehook.mouse.NativeMouseEvent;
import com.jin.lazytool.utils.JinUtils;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import org.luaj.vm2.LuaTable;

import java.awt.*;

public class MouseMotionEvent extends IEvent {

    private int x;
    private int y;

    public MouseMotionEvent(){}

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public MouseMotionEvent(NativeMouseEvent mouseEvent){
        this.x = mouseEvent.getX();
        this.y = mouseEvent.getY();
    }
    @Override
    public int execute(Robot robot, int index) throws InterruptedException,NoSuchMethodException {


        if(luaFLag){
            LuaTable lua = JinUtils.evalLua(getLua(), getTime());
            boolean exeFlag = lua.get("exeFlag").toboolean();
            if(exeFlag){
                Thread.sleep(lua.get("time").tolong());
                int x = lua.get("x").toint();
                int y = lua.get("y").toint();
                robot.mouseMove(x, y);

            }
        }else{
            Thread.sleep(getTime());
            robot.mouseMove(x, y);
        }
        return index;
    }
    @Override
    public Pane initDesc() {
        FlowPane pane = new FlowPane();
        pane.setStyle("-fx-pref-height: 26;");
        Label label = new Label("鼠标移动到: x: ");
        label.setTextFill(Color.TURQUOISE);
        TextField fieldx = new TextField(String.valueOf(x));
        TextField fieldy = new TextField(String.valueOf(y));
        fieldx.setStyle("-fx-pref-width: 80;");
        fieldy.setStyle("-fx-pref-width: 80;");
        fieldx.setEditable(false);
        fieldy.setEditable(false);
        pane.getChildren().addAll(label,fieldx,new Label("  y:"),fieldy);
        return pane;
    }


    @Override
    public void show() {

    }
}
